package com.ruoyi.web.money.common;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.StringJoiner;

/**
 * @author liyabin
 * @date 2021/3/16
 */
public interface CacheKey {

    String FUND_SUCCESS_KEY = "string:FUND.flag";

    String FUND_LIST_KEY = "list:fund";

    DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");

    /**
     * 生成缓存key
     *
     * @param keys 参数
     * @return
     */
    default String cacheKey(Object... keys) {
        if (keys != null && keys.length > 0) {
            StringJoiner result = new StringJoiner(":");
            Arrays.stream(keys).map(String::valueOf).forEach(result::add);
            return result.toString();
        } else {
            return null;
        }
    }

    /**
     * 获取 yyyyMMdd 日期
     *
     * @return 今天 yyyyMMdd
     */
    default String today() {
        return DATE_FORMATTER.format(LocalDateTime.now());
    }

}